package com.jsmile.cloud.tradecenter.settle.filter;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;

import lombok.extern.slf4j.Slf4j;

/**
 * 过滤器执行
 */
@Slf4j
public class SettlementFilterChain {

    private List<AbstractSettlementFilter> filters = Lists.newArrayList();

    public SettlementFilterChain addFilters(List<AbstractSettlementFilter> filters) {
        if (CollectionUtils.isNotEmpty(filters)) {
            this.filters.addAll(filters);
        }
        return this;
    }

    public SettlementFilterChain addFilter(AbstractSettlementFilter filter) {
        if (filter != null) {
            this.filters.add(filter);
        }
        return this;
    }

    public void settlement() {
        if (CollectionUtils.isEmpty(filters))
            return;
        // 排序
        // filters.sort(Comparator.comparingInt(f -> f.settleRule.getSort()));
        // 执行逻辑
        filters.stream().filter(x -> x.isSatisfied()).forEach(x -> {
            x.settlement();
        });
    }
}
